package com.yootk.action;

import com.yootk.common.action.abs.AbstractBaseAction;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 调整JVM运行参数
 * java -jar -Xmx4g -Xms4g -Xss256k -Xlog:gc -XX:+UseG1GC *.jar
 */
@RestController
@RequestMapping("/jvm/*")
public class MemoryAction extends AbstractBaseAction {

    @RequestMapping("memory")
    public Object memory() {
        Runtime runtime = Runtime.getRuntime();
        Map<String, Object> data = new HashMap<>();
        data.put("MaxMemory", runtime.maxMemory() / 1024 / 1024);
        data.put("TotalMemory", runtime.totalMemory() / 1024 / 1024);
        data.put("FreeMemory", runtime.freeMemory() / 1024 / 1024);
        return data;
    }
}
